package com.niit.bean;

import org.apache.hadoop.io.WritableComparable;


import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class ProvinceBean implements WritableComparable<ProvinceBean> {
    private String Province;//省份
    private String School;//学校
    private long ActiveDays;//活跃天数

    public ProvinceBean() {
    }

    public ProvinceBean(String Province, String School, long ActiveDays) {
        this.Province = Province;
        this.School = School;
        this.ActiveDays = ActiveDays;
    }

    public void set(String Province, String School, long ActiveDays) {
        this.Province = Province;
        this.School = School;
        this.ActiveDays = ActiveDays;
    }

    public String getProvince() {
        return Province;
    }

    public void setProvince(String Province) {
        this.Province = Province;
    }

    public String getSchool() {
        return School;
    }

    public void setSchool(String School) {
        this.School = School;
    }

    public long getActiveDays() {
        return ActiveDays;
    }

    public void setActiveDays(long ActiveDays) {
        this.ActiveDays = ActiveDays;
    }

    @Override
    public String toString() {
        return "省份：" + Province + ",学校：" + School + ",活跃天数：" + ActiveDays;
    }

    //todo 排序规则 根据州state正序进行排序 如果州相同 则根据确诊数量cases倒序排序
    @Override
    public int compareTo(ProvinceBean o) {
        int result;

        int i = Province.compareTo(o.getProvince());

        if (i > 0) {
            result = 1;
        } else if (i < 0) {
            result = -1;
        } else {
            // 确诊病例数倒序排序
            result = ActiveDays > o.getActiveDays() ? -1 : (ActiveDays < o.getActiveDays() ? 1 : 0);
        }

        return result;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(Province);
        dataOutput.writeUTF(School);
        dataOutput.writeLong(ActiveDays);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.Province = dataInput.readUTF();
        this.School = dataInput.readUTF();
        this.ActiveDays = dataInput.readLong();
    }
}
